<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
        }

        .box {
            width: 100px;
            height: 100px;
            background-color: red;
            position: absolute;
            transition: all 2s;
            border: 5px solid;
            left: 0px;
            top: 0px;
        }

        .container {
            width: 100px;
            height: 2000px;
        }
    </style>
</head>

<body>
    <div class="container"></div>
    <div class="box"></div>
    <script>
        var boxEle = document.querySelector(".box");
        boxEle.onclick = function () {
            //    var res =   innerWidth - this.offsetWidth;
            var res = document.documentElement.offsetWidth - this.offsetWidth;
            console.log(res);
            this.style.left = res + "px";
            var that = this;
            setTimeout(function () {
                // console.log("运动结束");
                // console.log(this);
                that.style.left = "0px";
            }, 2000);

        }


    </script>
</body>

</html>